/*
 * @Author: your name
 * @Date: 2021-12-22 14:23:46
 * @LastEditTime: 2021-12-22 20:40:36
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \json-serveg:\桌面2\50htmljs\sound\script.js
 */
// const sounds = ['applause', 'boo', 'gasp', 'tada', 'victory', 'wrong']

// sounds.forEach(sound=>{
//     const btn = document.createElement('button')
//     btn.classList.add('btn')
//     btn.innerText = sound
//     console.log(btn.innerText)
//     btn.addEventListener('click',()=>{
//         stopSongs()
//         document.getElementById(sound).play()
//     })
//     document.getElementById('buttons').appendChild(btn)
// })

// function stopSongs(){
//     sounds.forEach(sound =>{
//         const song = document.getElementById(sound)
//         song.pause()
//         song.currentTime =  0
//     })
// }

const btns = document.querySelectorAll('.btn')

btns.forEach(btn =>{
    btn.addEventListener('click',()=>{
        stop()
        document.getElementById(btn.innerText).play()
        // console.log(btn.innerText)
    })
})

function stop(){
    btns.forEach(btn=>{
        document.getElementById(btn.innerText).pause()
        document.getElementById(btn.innerText).currentTime= 0 
    })
}